<!doctype html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>Player</title>

		<meta
			name="viewport"
			content="width=device-width, initial-scale=1, maximum-scale=1"
		/>
		<link
			rel="icon"
			type="image/png"
			sizes="174x174"
			href="./favicon.png"
		/>

		<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.4.3/webcomponents-bundle.js"></script>
		<link
			href="https://fonts.googleapis.com/css?family=Material+Icons&display=block"
			rel="stylesheet"
		/>
		<script src="../build/Tone.js"></script>
		<script src="./js/tone-ui.js"></script>
		<script src="./js/components.js"></script>
		<style type="text/css">
			tone-play-toggle {
				margin-bottom: 10px;
			}
		</style>
	</head>
	<body>
		<tone-example label="Player">
			<tone-loader></tone-loader>
			<div slot="explanation">
				Click on the button to play the audio file on loop using
				<a href="https://tonejs.github.io/docs/latest/classes/Player"
					>Tone.Player</a
				>.
			</div>

			<div id="content">
				<tone-play-toggle></tone-play-toggle>
			</div>
		</tone-example>

		<script type="text/javascript">
			// the player
			const player = new Tone.Player({
				url: "https://tonejs.github.io/audio/loop/FWDL.mp3",
				loop: true,
				loopStart: 0.5,
				loopEnd: 0.7,
			}).toDestination();

			ui({
				tone: player,
				parent: document.querySelector("#content"),
			});

			// bind the interface
			document
				.querySelector("tone-play-toggle")
				.addEventListener("start", () => player.start());
			document
				.querySelector("tone-play-toggle")
				.addEventListener("stop", () => player.stop());
		</script>
	</body>
</html>
